package com.allwees.bs.module.mms.req.query;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.allwees.bs.core.modelbase.req.QueryReq;
import com.allwees.core.common.constant.EStatus;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Data
@EqualsAndHashCode(callSuper = true)
public class MerchantApplyQueryReq<M> extends QueryReq<M> {
    private EMerchantApplyStatus status;

    private Date createAtFrom;

    private Date createAtTo;

    protected String retailerUuid;

    @Override
    public void buildQuery(QueryWrapper<M> wrapper) {
        wrapper.and(StringUtils.isNotBlank(q), w -> {
            w.eq("company_name", q)
                    .or().eq("username", q)
                    .or().eq("phone", q)
                    .or().eq("email", q)
                    .or().eq("qq", q)
                    .or().eq("wechat", q);
        })
                .eq(StringUtils.isNotBlank(retailerUuid), "uuid", retailerUuid)
                .in("status", status.entityStatus());
    }

    private enum EMerchantApplyStatus {
        ALL {
            @Override
            List<Integer> entityStatus() {
                return Arrays.asList(
                        EStatus.WAIT_AUDIT.value(),
                        EStatus.MMS_FIRST_AUDIT_APPROVED.value(),
                        EStatus.NORMAL.value(),
                        EStatus.MMS_FIRST_AUDIT_REJECTED.value(),
                        EStatus.MMS_FINAL_AUDIT_REJECTED.value()
                );
            }
        },
        WAIT_FIRST_AUDIT {
            @Override
            List<Integer> entityStatus() {
                return Arrays.asList(
                        EStatus.WAIT_AUDIT.value()
                );
            }
        },
        WAIT_FINAL_AUDIT {
            @Override
            List<Integer> entityStatus() {
                return Arrays.asList(
                        EStatus.MMS_FIRST_AUDIT_APPROVED.value()
                );
            }
        },
        NORMAL {
            @Override
            List<Integer> entityStatus() {
                return Arrays.asList(
                        EStatus.NORMAL.value()
                );
            }
        },
        REJECTED {
            @Override
            List<Integer> entityStatus() {
                return Arrays.asList(
                        EStatus.MMS_FIRST_AUDIT_REJECTED.value(),
                        EStatus.MMS_FINAL_AUDIT_REJECTED.value()
                );
            }
        };

        abstract List<Integer> entityStatus();
    }
}
